package org.tinygroup.commons.tools;

import java.lang.reflect.Field;

public class ClassFiledUtil {
	/**
     * 判断clazz是否实现了interfaceClazz
     *
     * @param clazz
     * @param interfaceClazz
     * @return
     */
    public static boolean implmentInterface(Class<?> clazz, Class<?> interfaceClazz) {
        return interfaceClazz.isAssignableFrom(clazz);
    }
    
    
    /**
     * 从clazz及其父类中获取属性，如果找不到则返回null
     * @param clazz
     * @param name
     * @return
     */
    public static Field getDeclaredFieldWithParent(Class<?> clazz, String name) {
        try {
            return clazz.getDeclaredField(name);
        } catch (NoSuchFieldException e) {
            if (clazz.getSuperclass() != null) {
                return getDeclaredFieldWithParent(clazz.getSuperclass(), name);
            }
        }
        return null;

    }
}
